%% Read and Solve the Nonlinear Credibility Model
% by Jaromir Benes
%
% This m-file is fairly standard. We read the endogenous credibility model
% file, `credibility.model`, assign some parameters, compute steady state,
% solve the model, and save everything for future use. These steps are
% explained in other tutorials in more detail.

%% Clear Workspace

clear;
close all;
home;
irisrequired 20140401;
%#ok<*NOPTS>
 
%% Load and Calibrate Endogenous Credibility Model
%
% Call the function `model` to read the model file `credibility.model` and
% create a model object. Calibrate the model parameters. Note that the
% parameter `del`, which determines the convexity of the Phillips curve,
% must be greater than zero.

m = model('credibility.model');

m.alp = 0.5;
m.sgm = 0.1;
m.bet = 0.99;
m.gam = 0.05;
m.del = 0.4;
m.the = 0.80;
m.kap = 4;
m.phi = 0;
m.tau = 3;
m.rho = 2;
m.psi = 0.9;
m.omg = 1;

get(m,'parameters')

%% Find Steady State
%
% In nonlinear models, the steady-state must be calculated (numerically)
% first, before solving the model. By default, the function `sstate`
% assumes that the model does not have nonzero growth rates in any of its
% variables -- the `credibility.model` complies with this assumption. It is
% a good idea to always verify that the calculated steady-state holds
% <?chksstate?> (the function `chksstate` would throw an error message with
% the list of inaccurate equations).

m = sstate(m)
chksstate(m); %?chksstate?
ss = get(m,'sstate')

%% Compute First-Order Approximate Solution
%
% The first-order approximate solution matrices are not only used in
% linearized simulations, but they are also a point of departure for the
% exact nonlinear simulation mode.

m = solve(m)

%% Save Everything for Further Use

save read_model m ss;

%% Help on IRIS Functions Used in This File
%
% Use either `help` to display help in the command window, or `idoc`
% to display help in an HTML browser window.
%
%    help model
%    help model/model
%    help model/subsasgn
%    help model/sstate
%    help model/chksstate
%    help model/get
%    help model/solve
